package com.ccc.boot.security.service.impl;

import com.ccc.boot.log.ILogService;
import com.ccc.boot.log.LogInfo;
import com.ccc.boot.monitor.mapper.SysLogMapper;
import com.ccc.boot.entity.SysLog;
import com.ccc.boot.util.LogUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 登录日志表 业务处理实现类
 *
 * @author superC
 * @version 0.1.0
 * @date 2022-04-08
 */
@Service("logService")
public class LogServiceImpl implements ILogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    @Override
    public void saveLog(LogInfo info) {
        // 添加操作日志
        insertLog(info);
    }

    public boolean insertLog(LogInfo info) {
        SysLog sysLog = new SysLog();
        sysLog.setUsername(info.getUsername());
        sysLog.setIp(info.getIp());
        sysLog.setAddress(LogUtils.getAddress(info));
        sysLog.setIsp(info.getIsp());
        sysLog.setUserAgent(info.getUserAgent());
        sysLog.setMethod(info.getMethod());
        sysLog.setPath(info.getPath());

        return sysLogMapper.insert(sysLog) > 0;
    }

}
